unit JATUIF_Driver_Keyboard;

{$mode objfpc}{$H+}

interface

uses
    Classes, SysUtils, Keyboard;

Type
    TKeyboardDriver_Callback = procedure(Key:Char) of Object;

    { TKeyboardDriver }

    TKeyboardDriver = class(TObject)
      Public
        Constructor Create(Callback:TKeyboardDriver_Callback);
        Procedure Poll;
      Private
        KeyEvent:TKeyEvent;
        DriverCallback:TKeyboardDriver_Callback;
    end;

implementation

{ TKeyboardDriver }

constructor TKeyboardDriver.Create(Callback:TKeyboardDriver_Callback);
begin
     DriverCallback:= Callback;
     InitKeyboard;
end;

procedure TKeyboardDriver.Poll;
begin
     KeyEvent:= PollKeyEvent;
     If KeyEvent <> 0 then begin
        KeyEvent:=GetKeyEvent;
        KeyEvent:=TranslateKeyEvent(KeyEvent);
        DriverCallback(GetKeyEventChar(KeyEvent));
     end;
end;

end.

